import { Button, Checkbox, message, Form, Select, Input } from 'antd';
import { addData } from "../../apis/user"
import { useRef, useState } from 'react'
export default function Addfrom() {
  const [loading, b] = useState(false)
  const onFinish = (values) => {
    b(true)
    console.log('Success:', values);
    addData(values).then(res => {
      console.log(res);
      if (res.data.code == 1) {
        message.success("添加成功")
        b(false)
      } else {
        message.error(res.msg || "添加失败")
        b(false)
      }
    })
  };
  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };
  return (
    <div>
      <Form
        name="basic"
        labelCol={{
          span: 8,
        }}
        wrapperCol={{
          span: 16,
        }}
        style={{
          maxWidth: 600,
        }}
        initialValues={{
          userGroup: "普通管理员",
        }}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
        autoComplete="off"
      >
        <Form.Item
          label="账号"
          name="account"
          rules={[
            {
              required: true,
              message: '请输入账号!',
            },
          ]}
        >
          <Input placeholder="请输入账号" />
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"

          rules={[
            {
              required: true,
              message: '请输入密码!',
            },
          ]}
        >
          <Input.Password placeholder="请输入密码" />
        </Form.Item>

        <Form.Item
          label="管理员"
          name="userGroup"
          rules={[
            {
              required: true,
              message: '请选择管理员!',
            },
          ]}
        >
          <Select placeholder="请选择管理员"
          >
            <Select.Option value="普通管理员">普通管理员</Select.Option>
            <Select.Option value="超级管理员">超级管理员</Select.Option>
          </Select>
        </Form.Item>

        <Form.Item
          wrapperCol={{
            offset: 8,
            span: 16,
          }}
        >
          <Button loading={loading} type="primary" htmlType="submit">
            提交
          </Button>
        </Form.Item>
      </Form>
    </div>
  )
}
